#include "inc.h"

int g_iB = 0;

int main(int argc, char const *argv[])
{
    FILE *fpDst = fopen("06_test.txt", "w");

    static int s_iA = 0;
    int *p = malloc(sizeof(int));
    *p = 0;

    pid_t pid;
    pid = fork();

    if ( pid > 0 )
    {
        printf("Father Process, pid = %d\n", pid);
        fprintf(fpDst,"Father Process, pid = %d\n", pid );
        fflush(fpDst);

        g_iB = 1;
        s_iA = 1;
        *p = 1;
        printf("Father Data: g_iB = %d, s_iA = %d, *p = %d\n",
                g_iB, s_iA, *p );                
        fprintf(fpDst,"Father Data: g_iB = %d, s_iA = %d, *p = %d\n",
                g_iB, s_iA, *p );
        fflush(fpDst);

    }
    else if ( pid == 0 )
    {
        printf("Son    Process, pid = %d\n", pid);
        fprintf(fpDst,"Son    Process, pid = %d\n", pid);
        fflush(fpDst);

        printf("Son    Data: g_iB = %d, s_iA = %d, *p = %d\n",
                g_iB, s_iA, *p );
        fprintf(fpDst,"Son    Data: g_iB = %d, s_iA = %d, *p = %d\n",
                g_iB, s_iA, *p );
        fflush(fpDst);
       
       
    }

    fclose( fpDst );

    return 0;
}

/*
父进程和子进程打开同一个文件， 这个文件流是共享的。
所以父子进程都可以向这个文件写入信息。
文件流信息保存在PCB中
*/